<?php

namespace App\Exceptions;

use App\Http\Controllers\Web\RongshuController;
use App\Models\RequestLog;
use http\Env\Response;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
use App\Http\Services\Helper;

class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that are not reported.
     *
     * @var array
     */
    protected $dontReport = [
        //
    ];

    /**
     * A list of the inputs that are never flashed for validation exceptions.
     *
     * @var array
     */
    protected $dontFlash = [
        'current_password',
        'password',
        'password_confirmation',
    ];

    /**
     * Register the exception handling callbacks for the application.
     *
     * @return void
     */
    public function register()
    {
        $this->reportable(function (Throwable $e) {
            //
        });
    }

    public function report(Throwable $e)
    {

        //return parent::report($e); // TODO: Change the autogenerated stub
    }

    public function render($request, Throwable $e)
    {
        $path = $request->path();
        if (substr($path, 0, 7) == 'api/sip') {
            // 荣数系统的错误处理
            $error = $e->getMessage(). ':'. $e->getFile()." line".$e->getLine();
            $logId = $request->input('SIP_LOG_ID');
            $log = RequestLog::find($logId);
            $log->response = $error;
            $log->save();
            $this->wxnotice($error);
            // 张维喜的openid
            Helper::wxnotice(config('wechat.weixi_openid'), $error);
            return RongshuController::json1('501', '系统错误，错误信息：'.$error);
            // return response()->json(501,'系统错误，错误信息：'.$error);
        }

        return parent::render($request, $e); // TODO: Change the autogenerated stub
    }


}
